//
//  ByCellMyPetCard.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/26.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellMyPetCard.h"

// view
#import "ByViewPetCardRecordList.h"


@implementation ByCellMyPetCard
{
    UIImageView *_iconView;             // 商家图标
    UILabel     *_distanceLabel;        // 距离
    UILabel     *_nameLabel;            // 商家名称
    UILabel     *_moneyLabel;           // 余额
    
    UIControl   *_contactServiceView;   // 联系客服
    UIControl   *_recordView;           // 消费记录
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    // 图标
    _iconView = [UIImageView new];
    _iconView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self.contentView addSubview:_iconView];
    
    // 距离
    _distanceLabel = [[UILabel alloc] init];
    _distanceLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    _distanceLabel.text = @"300m";
    _distanceLabel.font = FONT(15);
    _distanceLabel.textAlignment = NSTextAlignmentRight;
    _distanceLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_distanceLabel];
    
    // 商家名称
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.numberOfLines = 2;
    _nameLabel.text = @"耐克旗舰店";
    _nameLabel.font = FONT(16);
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_nameLabel];
    
    // 在售商品数量
    _moneyLabel = [[UILabel alloc] init];
    _moneyLabel.text = @"余额：2000";
    _moneyLabel.font = FONT(15);
    _moneyLabel.textAlignment = NSTextAlignmentLeft;
    _moneyLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_moneyLabel];
    
    // 联系客服
    _contactServiceView = [[UIControl alloc] init];
    _contactServiceView.backgroundColor = BY_RED_COLOR;
    _contactServiceView.layer.cornerRadius = 18;
    [self.contentView addSubview:_contactServiceView];
    //
    UIImageView *serviceIconView = [UIImageView new];
    serviceIconView.image = [UIImage imageNamed:@"客服"];
    [_contactServiceView addSubview:serviceIconView];
    //
    UILabel *serviceLabel = [[UILabel alloc] init];
    serviceLabel.text = @"联系客服";
    serviceLabel.font = FONT(14);
    serviceLabel.textAlignment = NSTextAlignmentCenter;
    serviceLabel.textColor = BY_GOLD_COLOR;
    [_contactServiceView addSubview:serviceLabel];
    
    // 消费记录
    _recordView = [[UIControl alloc] init];
    _recordView.backgroundColor = BY_THEME_COLOR;
    _recordView.layer.cornerRadius = 18;
    [_recordView addTarget:self action:@selector(lookRecord) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_recordView];
    //
    UIImageView *recordIconView = [UIImageView new];
    recordIconView.image = [UIImage imageNamed:@"消费记录"];
    [_recordView addSubview:recordIconView];
    //
    UILabel *recordLabel = [[UILabel alloc] init];
    recordLabel.text = @"消费记录";
    recordLabel.font = FONT(14);
    recordLabel.textAlignment = NSTextAlignmentCenter;
    recordLabel.textColor = BY_GOLD_COLOR;
    [_recordView addSubview:recordLabel];
    
    
    
    // 布局
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@0);
        make.bottom.equalTo(@0);
        make.width.equalTo(_iconView.mas_height);
    }];
    [_distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(_iconView);
        make.height.equalTo(@20);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(10);
        make.top.equalTo(@10);
        make.right.lessThanOrEqualTo(_contactServiceView.mas_left).offset(-10);
    }];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(10);
        make.bottom.equalTo(@-10);
        make.right.equalTo(_nameLabel);
    }];
    [_contactServiceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.height.equalTo(@36);
        make.width.equalTo(@100);
        make.bottom.equalTo(_iconView.mas_centerY).offset(-5);
    }];
    [serviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(@0);
        make.width.equalTo(@65);
        make.right.equalTo(@(-5));
    }];
    [serviceIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.right.equalTo(serviceLabel.mas_left).offset(0);
        make.centerY.equalTo(@0);
        make.left.equalTo(@8);
    }];
    [_recordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.right.equalTo(_contactServiceView);
        make.top.equalTo(_iconView.mas_centerY).offset(5);
    }];
    [recordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.left.equalTo(serviceLabel);
        make.centerY.equalTo(@0);
    }];
    [recordIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.left.equalTo(serviceIconView);
        make.centerY.equalTo(@0);
    }];
}

- (void)lookRecord {
    
    ByViewPetCardRecordList *view = [ByViewPetCardRecordList new];
    [view show];
}

@end
